package com.neusoft.yuejian_6.activity;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.MediaController;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.adapter.VideoAdapter;
import com.neusoft.yuejian_6.javabean.Video;
import com.neusoft.yuejian_6.model.VideoModel;

import org.junit.internal.Classes;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class VideosActivity extends Activity {
    private ImageView left;
    private RecyclerView recyclerView;
    private VideoAdapter adapter;
    private MediaController mediaController;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        setContentView(R.layout.activity_videos);

        initView();
        getVideo();
        initEvent();
    }

    private void initView() {

        recyclerView = (RecyclerView) findViewById(R.id.club_video);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局
        left = (ImageView) findViewById(R.id.left);

    }
    private void initEvent() {


        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();}
        });
    }

    private void getVideo(){
        Bundle bundle = this.getIntent().getExtras();
        int club_id = bundle.getInt("club_id");
        VideoModel videoModel = new VideoModel();
        Call call = videoModel.getVideos(club_id);
        call.enqueue(new Callback<List<Video>>() {
            @Override
            public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
                //mDataList= (List) response.body();
                List<Video> data=response.body();
                System.out.printf("data");
                recyclerView.setAdapter(new VideoAdapter(VideosActivity.this,data));
            }

            @Override
            public void onFailure(Call<List<Video>> call, Throwable t) {
                //  Toast.makeText(getActivity(), "fail", Toast.LENGTH_SHORT).show();
            }
        });

    }
}
